<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>get</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C++ I/O</a> &gt; <a href="get.html">get</a>
  </div>

  <div class="name-format">
    get
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;fstream&gt;
  int get();
  istream&amp; get( char&amp; ch );
  istream&amp; get( char* buffer, streamsize num );
  istream&amp; get( char* buffer, streamsize num, char delim );
  istream&amp; get( streambuf&amp; buffer );
  istream&amp; get( streambuf&amp; buffer, char delim );
</pre>

  <p>The get() function is used with input streams, and either:</p>

  <ul>
    <li>reads a character and returns that value,</li>

    <li>reads a character and stores it as <em>ch</em>,</li>

    <li>reads characters into <em>buffer</em> until <em>num</em> - 1
    characters have been read, or <strong>EOF</strong> or newline
    encountered,</li>

    <li>reads characters into <em>buffer</em> until <em>num</em> - 1
    characters have been read, or <strong>EOF</strong> or the
    <em>delim</em> character encountered (<em>delim</em> is not read
    until next time),</li>

    <li>reads characters into buffer until a newline or
    <strong>EOF</strong> is encountered,</li>

    <li>or reads characters into buffer until a newline,
    <strong>EOF</strong>, or <em>delim</em> character is encountered
    (again, <em>delim</em> isn&#39;t read until the next get() ).</li>
  </ul>

  <p>For example, the following code displays the contents of a file
  called temp.txt, character by character:</p>
  <pre class="example-code">
   char ch;
   ifstream fin( &quot;temp.txt&quot; );
   while( fin.get(ch) )
     cout &lt;&lt; ch;
   fin.close();         
</pre>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="gcount.html">gcount</a><br>
    <a href="getline.html">getline</a><br>
    (C++ Strings) <a href="../cppstring/getline.html">getline</a><br>
    <a href="ignore.html">ignore</a><br>
    <a href="peek.html">peek</a><br>
    <a href="put.html">put</a><br>
    <a href="read.html">read</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
